package com.ylbh.modules.sign.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.sign.dto.SignDailyTasksDTO;
import com.ylbh.common.pojo.sign.dto.SignTurntableDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.sign.entity.ShoppingSigninDailyTask;
import com.ylbh.modules.sign.entity.ShoppingSigninTurntableInfo;
import com.ylbh.modules.sign.service.ShoppingDailyTasksService;
import com.ylbh.modules.sign.service.ShoppingSignTurntableService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author; wjc
 * @date: 2019/12/17
 */
@RestController
@RequestMapping("task")
public class ShoppingSignDailyTasksController {

    @Autowired
    private ShoppingDailyTasksService shoppingDailyTasksService;

    @ApiOperation("每日/成长任务例表")
    @GetMapping("queryDailyTasksList")
    public CommonResult<PageUtils> queryDailyTasksList(SignDailyTasksDTO signDailyTasksDTO ) {
        PageUtils DailyTasksList = shoppingDailyTasksService.queryDailyTasksList(signDailyTasksDTO);
        return Ref.ok(DailyTasksList);
    }

    @RequestMapping("addDailyTasks")
    public CommonResult addDailyTasks(@RequestBody SignDailyTasksDTO signDailyTasksDTO) {
        shoppingDailyTasksService.addDailyTasks(signDailyTasksDTO);
        return Ref.ok();
    }

    @SysLog("获取每日/成长任务信息ById")
    @RequestMapping("getDailyTasksById/{id}")
    public CommonResult getDailyTasksById(@PathVariable(value = "id") String id) {
        ShoppingSigninDailyTask dailyTask = shoppingDailyTasksService.getDailyTasksById(id);
        return Ref.ok(dailyTask);
    }

    @SysLog("根据ID修改每日/成长任务信息")
    @ApiOperation("根据ID修改每日/成长任务信息")
    @RequestMapping("modifyDailyTasksById")
    public CommonResult modifyTurntableById(@RequestBody SignDailyTasksDTO signDailyTasksDTO) {
        shoppingDailyTasksService.modifyTurntableById(signDailyTasksDTO);
        return  Ref.ok();
    }

    @SysLog("删除任务信息")
    @ApiOperation("删除任务信息")
    @RequestMapping("removeDailyTasksById/{id}")
    public CommonResult<Void> removeDailyTasksById(@PathVariable(value = "id") String id){
        shoppingDailyTasksService.removeDailyTasksById(id);
        return Ref.ok();
    }

    @SysLog("修改任务状态")
    @ApiOperation("修改任务状态")
    @RequestMapping("modifyTaskEnableStateById")
    public CommonResult<Void> modifyTaskEnableStateById(@RequestBody SignDailyTasksDTO signDailyTasksDTO){
        shoppingDailyTasksService.modifyTaskEnableStateById(signDailyTasksDTO);
        return Ref.ok();
    }

    @RequestMapping("uploadImg")
    public CommonResult<String> uploadImg(MultipartFile file, HttpServletRequest request) {
        String url = shoppingDailyTasksService.uploadImg(file, request);
        return Ref.ok(url);
    }
}
